package com.yy.wga.common.util.common;


import lombok.extern.slf4j.Slf4j;

/**
 * 环境变量工具类
 *
 * @author <a href="mailto:ludezh@dingtalk.com"> ludezh </a>
 * @version 1.0.0   2019/3/23,15:29
 * @since 1.0.0     2019/3/23,15:29
 */
@Slf4j
public class EnvUtils {
    private static org.springframework.core.env.Environment environment = SpringUtils.getBean(org.springframework.core.env.Environment.class);

    /**
     * 根据配置参数获取配置值
     *
     * @param key
     * @return
     */
    public static String get(String key) {
        String value = "";
        try {
            value = environment.getProperty(key);
        } catch (Exception e) {
            log.error("获取配置值异常：", e);
        }
        return value;

    }

    /**
     * 根据配置参数获取配置值
     *
     * @param p
     * @return
     */
    public static Integer getInt(String p) {
        Integer intVal = 0;
        try {
            intVal = Integer.parseInt(environment.getProperty(p));
        } catch (Exception e) {
            log.error("获取配置值异常：", e);
        }
        return intVal;
    }

    /**
     * 根据key获取值,并转换为对应数据类型
     *
     * @param property
     * @param cla
     * @param <T>
     * @return
     */
    public static <T> T get(String property, Class<T> cla) {
        return environment.getProperty(property, cla);
    }
}
